package facade;

import java.io.Serializable;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import model.Person;

/**
 *
 * @author Turk
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class RecruiterFacade implements Serializable {

    @PersistenceContext(unitName = "MyGronaPU")
    private EntityManager em;

    public RecruiterFacade() {
    }

    public boolean recruiterLogin(String u, String p) {
        boolean result = false;
        try {
            Query q = em.createQuery("SELECT a "
                    + "FROM Person a "
                    + "WHERE a.username = '" + u + "' "
                    + "AND a.password = '" + p + "'",
                    Person.class);
            Person per = (Person) q.getSingleResult();
            if ((q.getSingleResult() != null)) {
                System.out.println("Login success !");
                result = true;
            }
        } catch (Exception e) {
            System.out.println("Query didn't execute properly´\n" + e);
        } finally {
            em.clear();
        }
        return result;
    }
}
